<template>
  <view>
    <u-navbar title="我的维修单" :is-back="false"></u-navbar>
<!--    <view class="searchBox">-->
<!--      <view style="width: 20%;display: inline-block">-->
<!--        <uni-combox :candidates="searchTypes" placeholder="请选择搜索类型" v-model="searchType"></uni-combox>-->
<!--      </view>-->
<!--      <view style="width: 80%;display: inline-block">-->
<!--        <uni-search-bar @confirm="search"  v-model="searchValue" ></uni-search-bar>-->
<!--      </view>-->
<!--    </view>-->
    <swipe-direct
        :lr-distance="30"
        left-med="leftMethod"
        right-med="rightMethod"
        @leftMethod="leftMethod"
        @rightMethod="rightMethod">
      <uni-segmented-control styleType="text" :current="current" :values="items" @clickItem="onClickItem"
                             activeColor="#007aff"></uni-segmented-control>

      <view class="content">
        <repair-card :repair-data="repairData"
                     :actions="cardActions"
                     @evaluate="evaluate"
                     @contact="call"
        ></repair-card>
        <uni-load-more v-if="queryParams.pageSize<repairData.length" color="#007AFF" :status="status" />
      </view>
    </swipe-direct>
  </view>
</template>

<script>
import {RepairOrderService} from "../public/repairApplication/repairOrderService";
import RepairCard from "../../components/RepairCard";
import SwipeDirect from "../../components/swiper-direct";

export default {
  components: {SwipeDirect, RepairCard},
  data() {
    return {
      items: ['全部', '进行中', '待评价', "已完成","已退单"],
      statusList: [[undefined], [0, 1, 2], [3], [4],[5]],
      current: 1,
      cardActions: [
        {
          title: "联系维修员",
          icon: "phone",
          method: "contact",
          showStandard: "currentState",
          value: [1, 2]
        },
        {
          title: "催单",
          icon: "notification",
          method: "notification",
          showStandard: "currentState",
          value: [1, 2]
        },
        {
          title: "评价",
          icon: "chat",
          method: "evaluate",
          showStandard: "currentState",
          value: [3,4]
        },

      ],
      refreshIfNeeded:false,
      repairData: [],
      searchValue:"",
      searchTypes: ['北京', '南京', '东京', '武汉', '天津', '上海', '海口'],
      searchType:"",
      totalCount:100,
      queryParams: {
        currentPage: 1,
        pageSize: 5,
        filters: {
          repairApplicantId: uni.getStorageSync('userInfo').eid,
          currentState:[0, 1, 2].join("$|$")
        },
        orderBys: [
          {
            property: "createDatetime",
            order: "desc"
          }
        ]
      },
      status:"more"
    }
  },
  watch:{
    refreshIfNeeded: {
      handler(newValue, oldValue) {
        if(newValue){
          this.refreshIfNeeded=false;
          this.init(0);
        }
      },

      deep: true
    }
  },
  created() {
    this.init(0)
    uni.$on("onReachBottom",()=>{
      //触底业务逻辑
      if(this.queryParams.pageSize*this.queryParams.currentPage>=this.totalCount){
        this.status="nomore"
        return;
      }
      this.queryParams.currentPage++;
      this.init(1);
    })
  },
  destroyed(){
    uni.$off("onReachBottom")
  },
  methods: {
    init(type) {
      //0代表初始化 1代表加载更多
      this.status="loading"
      if(type==0){this.repairData=[];this.queryParams.currentPage=1}
      RepairOrderService.findRepairOrders(this.queryParams).then(res => {
        // console.log("data",res.data)
        //拼接数组
        this.repairData=this.repairData.concat( res.data.datas);
        this.totalCount=res.data.totalCount;
        this.status='more'
      })
    },
    onClickItem(e) {
      if (this.current != e.currentIndex) {
        this.current = e.currentIndex;
        this.queryParams.filters.currentState = this.current != 0 ? this.statusList[this.current].join("$|$") : null;
        this.init(0)
      }
    },
    evaluate(param) {
      console.log("parm", param)
      uni.navigateTo({
        //保留当前页面，跳转到应用内的某个页面
        url: '/pages/normalUser/public/Evaluate/index?id='+param.eid+"&repairmanId="+param.repairmanId
      })
    },
    call(param) {
      console.log(param.repairmanPhone)
      uni.makePhoneCall({
        phoneNumber: param.repairmanPhone //仅为示例
      });
    },
    search(){

    },
    leftMethod(){
      if(this.current==this.items.length-1){
        this.current=-1;
      }
      this.onClickItem({"currentIndex":this.current+1})
    },
    rightMethod(){
      if(this.current==0){
        this.current=this.items.length;
      }
      this.onClickItem({"currentIndex":this.current-1})
    }
  }
}
</script>

<style>
.segmented-control__item {
  background-color: white;
}
.searchBox{
  width: 100%;
  background-color: white;
}
</style>
